package com.hardydou.system.model;

import com.hardydou.common.constant.Const;
import com.hardydou.framework.quartz.QuartzTask;

import java.io.Serializable;
import java.util.Date;

/**
 * @author ：hardy
 * @description：SystemTask
 * @date ：Created in 2020/6/25
 * @Copyright ：Hardydou.com
 */
public class SystemTask extends BaseModel {

    private Long taskId;

    private String taskName;

    private String taskGroup;

    private String taskClass;

    private String invokeParam;

    private String taskCron;

    private String timeZone;

    private Integer status;

    private static final long serialVersionUID = 1L;

    public Long getTaskId() {
        return taskId;
    }

    public void setTaskId(Long taskId) {
        this.taskId = taskId;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName == null ? null : taskName.trim();
    }

    public String getTaskGroup() {
        return taskGroup;
    }

    public void setTaskGroup(String taskGroup) {
        this.taskGroup = taskGroup == null ? null : taskGroup.trim();
    }

    public String getTaskClass() {
        return taskClass;
    }

    public void setTaskClass(String taskClass) {
        this.taskClass = taskClass;
    }

    public String getInvokeParam() {
        return invokeParam;
    }

    public void setInvokeParam(String invokeParam) {
        this.invokeParam = invokeParam == null ? null : invokeParam.trim();
    }

    public String getTaskCron() {
        return taskCron;
    }

    public void setTaskCron(String taskCron) {
        this.taskCron = taskCron == null ? null : taskCron.trim();
    }

    public String getTimeZone() {
        return timeZone;
    }

    public void setTimeZone(String timeZone) {
        this.timeZone = timeZone == null ? null : timeZone.trim();
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", taskId=").append(taskId);
        sb.append(", taskName=").append(taskName);
        sb.append(", taskGroup=").append(taskGroup);
        sb.append(", taskClass=").append(taskClass);
        sb.append(", invokeParam=").append(invokeParam);
        sb.append(", taskCron=").append(taskCron);
        sb.append(", timeZone=").append(timeZone);
        sb.append(", status=").append(status);
        sb.append(", remark=").append(remark);
        sb.append(", ctime=").append(ctime);
        sb.append(", utime=").append(utime);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }

    private QuartzTask task = new QuartzTask();

    public QuartzTask toQuartzTask() {
        task.setTaskGroup(getTaskGroup());
        task.setTaskName(getTaskName());
        task.setTaskClass(getTaskClass());
        task.setInvokeParam(getInvokeParam());
        task.setCronExpression(getTaskCron());
        task.setRemark(getRemark());
        return task;
    }

    public boolean isOn() {
        return getStatus().equals(Const.Status.NORMAL.val);
    }
}